package com.lh.tams.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lh.tams.domain.TamsDept;
import com.lh.tams.service.DeptService;
import com.lh.tams.util.DataGridModel;
import com.lh.tams.util.ID;
import com.lh.tams.util.Page;
import com.lh.tams.util.Status;
import com.lh.tams.util.diy.Json;

@RequestMapping("/dept")
@Controller
public class DeptController {
	
	private DeptService deptService;

	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}
	
	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(DataGridModel dgm,TamsDept dept){
		return deptService.query(dgm, dept);
	}
	
	@RequestMapping("/add.adm")
	@ResponseBody
	public Json add(TamsDept dept,long parentId){
		if(parentId>0){
			TamsDept tamsDept = new TamsDept(parentId);
			dept.setTamsDept(tamsDept);
		}
		dept.setIdBgt(ID.next());
		dept.setDeptStatus(Status.STATUS_NORMAL);
		
		deptService.add(dept);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/update.adm")
	@ResponseBody
	public Json update(TamsDept dept,long parentId){
		if(parentId>0){
			TamsDept tamsDept = new TamsDept(parentId);
			dept.setTamsDept(tamsDept);
		}
		dept.setDeptStatus(Status.STATUS_NORMAL);
		deptService.update(dept);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/del.adm")
	@ResponseBody
	public Json delete(long[] id){
		deptService.delete(id);
		return new Json();
	}
	
}
